package com.google.codejam;

import hu.mapro.jam.commons.Input;
import hu.mapro.jam.commons.Problem;

/**
 *  Using <a href="http://code.google.com/p/maprohu-codejam-lib/">Google Code Jam library</a>. 
 */
public class PasswordProblem extends Problem {

	public PasswordProblem() {
		super("A", true);
	}

	@Override
	protected String solve(Input in) {
		int[] ints = in.integers();

		int A = ints[0];
		int B = ints[1];
		
		double[] p = in.doubles();
		
		double r;
		
		r = 1 + B + 1; // give up
		
		for (int i=0 ; i<=A ; i++) {
			
			double pc = 1;
			
			for (int j=0 ; j<A-i ; j++) {
				pc *= p[j];
			}
			
			int nc = i + (B-A+i) + 1;

			double pi = 1-pc;
			
			int ni = nc + B + 1;
			
			r = Math.min(r, pc*nc + pi*ni);
			
		}
		
		return Double.toString(r);
	}

}
